package com.bbznb.controller;

import com.bbznb.common.Result;
import com.bbznb.entity.UserRegister;
import com.bbznb.service.LoginService;
import com.bbznb.util.User;
import com.bbznb.util.UserToken;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/auth")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @PostMapping( "/login")
    public Result login(@RequestBody User user) {
        String username = user.getUsername();
        String password = user.getPassword();
        System.out.println( user.getUsername());
        System.out.println( user.getPassword());
        UserToken userToken = loginService.login( username, password );
        return Result.build(200, "success", userToken);
    }

    @RequestMapping("/register")
    public Result register(@RequestBody UserRegister userRegister) {
        loginService.register(userRegister);
        return Result.build(200, "success", null);

    }


}
